package com.zm.zyz.servlet;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.zm.zyz.util.MyBatisHelper;
import com.zm.zyz.mapper.ZyzTaskMapper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/queryTask")
public class QueryTaskServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession session = MyBatisHelper.getSession();
        int p = Integer.parseInt(req.getParameter("page"));
        System.out.println(p);

        ZyzTaskMapper taskMapper = session.getMapper(ZyzTaskMapper.class);
        Page page = Page.of(p,8);
        page = taskMapper.selectPage(page,null);
        Gson gson = new Gson();
        String json = gson.toJson(page);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().println(json);
        session.close();



    }
}
